// 486. 预测赢家


function PredictTheWinner(nums: number[]): boolean {


    function recrusion(l:number,h:number,turn:number):number {
        if(l==h){
            return nums[l]*turn
        }
        const front = nums[l]*turn + recrusion(l+1,h,-turn)
        const end = nums[h]*turn + recrusion(l,h-1,-turn)
        return Math.max(front*turn,end*turn)*turn

    }

    return recrusion(0,nums.length-1,1)>=0
};

const ans =PredictTheWinner([1,5,2])
console.log(ans)